home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 June / maximum-cd-1999-06.iso / Fireworks 2 / data1.cab / Dreamweaver_2_Files / Configuration / Behaviors / Actions / Group Down.js < prev    next >
Encoding:
JavaScript  |  1999-03-01  |  22.5 KB  |  627 lines

  1. //*************** GLOBALS VARS *****************
  2.  
  3.  
  4. //******************* BEHAVIOR FUNCTIONS **********************
  5.  
  6.  
  7. function GrpDown(grp){
  8.     var i,j=0,downSrc,downOver,objName;
  9.     var cmd = "'" + grp + "'";
  10.     var docGroup=false;
  11.     for (i=1; i < (GrpDown.arguments.length-2); i+=3) {
  12.         objName = GrpDown.arguments[i];
  13.         downSrc = GrpDown.arguments[i+1];
  14.         downOver = GrpDown.arguments[i+2];
  15.         if(!downOver) downOver = downSrc;
  16.         var docGroup = FindGroup(grp, objName);
  17.         if (!docGroup || !downSrc) continue;
  18.         obj = FWFindImage(document,objName,0);
  19.         if (!obj) continue;
  20.         obj.atRestSrc = downSrc; obj.downOver = downOver;
  21.         obj.src = downOver; obj.isDown = true;
  22.         obj.skipMe = true;
  23.         cmd += ",'" + objName + "','" + downSrc + "','" + downOver + "'";
  24.         j++;
  25.     }
  26.     setCookie(grp, cmd);
  27.     if (!docGroup) return;
  28.     var theImages = docGroup.theImages;
  29.     if (theImages) {
  30.         for (i=0; i<theImages.length; i++) {
  31.             var curImg = theImages[i];
  32.             if (curImg && !curImg.skipMe) {
  33.                 curImg.atRestSrc = curImg.initialSrc;
  34.                 curImg.isDown = false; curImg.downOver = false;
  35.                 curImg.src = curImg.initialSrc;
  36.             }
  37.             curImg.skipMe = false;
  38.         }
  39.     }
  40. }
  41. function FWFindImage(doc, name, j)
  42. {
  43.     var theImage=false;
  44.     if (doc.images) {
  45.         theImage = doc.images[name];
  46.     }
  47.     if (theImage) return theImage;
  48.     if (doc.layers) {
  49.         for (j=0; j<doc.layers.length; j++) {
  50.             theImage = FWFindImage(doc.layers[j].document, name, 0);
  51.             if (theImage) return(theImage);
  52.         }
  53.     }
  54.     return(false);
  55. }
  56.  
  57. function setCookie(name, value) {
  58.    document.cookie = name + "=" + escape(value)
  59. }
  60.  
  61. function getCookie(Name) {
  62.    var search = Name + "="
  63.    var retVal = "";
  64.    if (document.cookie.length > 0) { // if there are any cookies
  65.      offset = document.cookie.indexOf(search);
  66.      if (offset != -1) { // if cookie exists 
  67.          // set index of beginning of value
  68.          end = document.cookie.indexOf(";", offset) 
  69.          // set index of end of cookie value
  70.          offset += search.length 
  71.          if (end == -1) 
  72.             end = document.cookie.length;
  73.          retVal = unescape(document.cookie.substring(offset, end)) ;
  74.      } 
  75.    }
  76.    return(retVal);
  77. }
  78.  
  79. function InitGrp(grp) {
  80.     var cmd = false; if (getCookie) cmd = getCookie(grp);
  81.     if (cmd) {
  82.         eval("GrpDown("+cmd+")");
  83.         eval("GrpRestore("+cmd+")");
  84.     }
  85. }
  86. function FindGroup(grp, imageName) {
  87.     var img = FWFindImage(document, imageName, 0);
  88.     if (!img) return(false);
  89.     var docGroup = eval("document.FWG_"+grp);
  90.     if (!docGroup) {
  91.         docGroup = new Object;
  92.         eval("document.FWG_"+grp+" = docGroup");
  93.         docGroup.theImages = new Array;
  94.     }
  95.     if (img) {
  96.         var i;
  97.         for (i=0; i<docGroup.theImages.length; i++) {
  98.             if (docGroup.theImages[i] == img) break;
  99.         }
  100.         docGroup.theImages[i] = img; 
  101.         if (!img.atRestSrc) {
  102.             img.atRestSrc = img.src;
  103.             img.initialSrc = img.src;
  104.         }
  105.     }
  106.     return(docGroup);
  107. }
  108. function GrpRestore(grp){
  109.     var docGroup = eval("document.FWG_"+grp);if (!docGroup) return;
  110.     theImages = docGroup.theImages;
  111.     if (theImages) {
  112.         for (i=0; i<theImages.length; i++) {
  113.             var curImg = theImages[i];
  114.             if (curImg.atRestSrc) {
  115.                 curImg.src = curImg.atRestSrc;
  116.             }
  117.         }
  118.     }
  119. }
  120.  
  121. //Preloads multiple images files in order. Accepts a variable number of args
  122. //(each should be quoted):
  123. //  imgURL   - an image filename, URL encoded. (ex: file.gif, http://www.x.com/y.gif)
  124. //
  125. //Creates a new array of Image objects. With each one, it assigns an image source
  126. //from the argument list. These are downloaded essentially simultaneously into the
  127. //client cache. When the user needs a new image file (for example: they go to the
  128. //next web page), the browser should quickly find this image in the cache.
  129. //!!! IMPORTANT !!! This function is also defined in file "Preload Images.htm".
  130. //Any edits must be made there as well as here.
  131.  
  132. function MM_preloadImages() { //v2.0
  133.   if (document.images) {
  134.     var imgFiles = MM_preloadImages.arguments;
  135.     if (document.preloadArray==null) document.preloadArray = new Array();
  136.     var i = document.preloadArray.length;
  137.     with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
  138.       preloadArray[i] = new Image;
  139.       preloadArray[i++].src = imgFiles[j];
  140.   } }
  141. }
  142.  
  143.  
  144.  
  145. //******************* API **********************
  146.  
  147.  
  148. //Checks for the existence of images.
  149. //If none exist, returns false so this Action is grayed out.
  150.  
  151. function canAcceptBehavior(){
  152.   var retVal = "";
  153.   var imgs = getAllObjectRefs("IE 4.0","IMG");
  154.   if (imgs.length > 0) {
  155.    retVal = "onClick";
  156.   }
  157.   if (retVal)
  158.     return retVal;
  159.   return false;
  160. }
  161.  
  162.  
  163.  
  164. //Returns Javascript functions to be inserted in HTML head with script tags.
  165.  
  166. function behaviorFunction(){       
  167.   return "MM_preloadImages,FindGroup,InitGrp,GrpRestore,getCookie,setCookie,FWFindImage,GrpDown"
  168. }
  169.  
  170.  
  171.  
  172. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  173. //Gets list of imgSrcs from doc attribute. With each imgSrc, it gets the parallel
  174. //img name from select 'menu'. Each imgSrc & imgObj are embedded as args.
  175. function applyBehavior() {
  176. /*
  177.     return "grpOver('Joe', 'Foo', 'foo.img');"
  178. }
  179. */
  180.   var retVal="",i,j,argList="",fnArray,imgSrcArray,imgSrc,imgObj,imgObjIE,newName;
  181.   var imgObjsArray=document.MM_imgObjsArray;
  182.   var img2Src,imgList="";
  183.  
  184.   grpName = document.theForm.grpName.value;
  185.   imgSrcArray = document.MM_myImgSrcs;      //get global list of imgSrcs
  186.   for (i=0; i<imgSrcArray.length; i++) {    //with each imgSrc
  187.     imgSrc = imgSrcArray[i];
  188.     img2Src = document.MM_myImgSrcs2[i];
  189.     if (imgSrc) {      //if not empty
  190.       if (argList) argList += ",";    //if stuff already in list, add comma
  191.       theName = imgObjsArray[i].getAttribute("name");
  192.       if (!theName){  //if the image is unnamed
  193.         //from this array, get unique image name
  194.         newName = getUniqueName("IMG","Image",imgObjsArray); 
  195.         imgObjsArray[i].setAttribute("name",newName); //rename image in document
  196.       }
  197.       theName = imgObjsArray[i].getAttribute("name");
  198.       argList += "'"+escape(theName)+"','"+escape(imgSrc)+"','" + escape(img2Src) + "'";
  199.       imgList += (imgList?",":"")+"'"+escape(imgSrc)+"','" + escape(img2Src) + "'";
  200.        break;
  201.     }
  202.   }
  203.   if (!argList) retVal = MSG_NoImgsSelected;
  204.   else { //OK
  205.     //Add or remove MM_swapImgRestore() based on checkbox setting
  206.     selObj = dreamweaver.getBehaviorElement();
  207.     if (!selObj){
  208.       selArr = dreamweaver.getSelection();
  209.       selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  210.     
  211.     }
  212.  
  213.     //Add or remove MM_preloadImages() based on checkbox setting
  214.     var obj = dreamweaver.getDocumentDOM("document").body;
  215.     if (document.theForm.preload.checked) { //add preload call to onLoad handler
  216.       argList += ",\'"+document.preloadId+"\'"; //add uniqueName to main fn call
  217.       setHandler(obj,"onLoad","MM_preloadImages("+imgList+",'"+document.preloadId+"')",document.preloadId);
  218.     } else {
  219.       delHandler(obj,"onLoad","MM_preloadImages",document.preloadId);
  220.     }
  221.     var theInit = "InitGrp('" + grpName + "')";
  222.     setHandler(obj, "onLoad", theInit, grpName);
  223.  
  224.     if (document.theForm.restore) {
  225.       var theRestore = "GrpRestore('" + grpName + "')";
  226.       if (document.theForm.restore.checked) { //add restore to onMouseOut handler
  227.         setHandler(selObj,'onMouseOut',theRestore);
  228.       } else { //remove it
  229.         delHandler(selObj,'onMouseOut', 'GrpRestore', grpName);
  230.       }
  231.     }
  232.  
  233.     retVal = "GrpDown('"+grpName+"'," + argList+")";  //create correct function call
  234.   }
  235.     return retVal
  236. }
  237.  
  238.  
  239. //Given the original function call, this parses out the args and updates
  240. //the UI. Loops through each imgObj,imgSrc pair.
  241. //If imgObj already present in menu, stuff imgSrc in imgSrcArray. If imgObj
  242. //doesn't exist, add to menu, and extend imgSrcArray.
  243.  
  244. function inspectBehavior(behFnCallStr){
  245.   var argArray,imgSrcArray,imgSrcArray2,found,numImgs,i,imgObj,imgSrc,imgSrc2,j,imgObjNum;
  246.   var imgsArray = document.MM_imgObjsArray = createObjsArray("IMG");
  247.  
  248.   argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
  249.   imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
  250.   imgSrcArray2 = document.MM_myImgSrcs2; //get the prior list of imgSrcs
  251.   group=unescQuotes(argArray[1]);
  252.   numImgs = document.MM_imgObjsArray.length;
  253.   for (i=2; i<(argArray.length-2); i+=3){ //with each imgObj,imgSrc pair
  254.     imgName=unescQuotes(argArray[i]);
  255.     imgSrc=unescape(argArray[i+1]);
  256.     imgSrc2=unescape(argArray[i+2]);
  257.     found = false;
  258.     for (j=0; j<numImgs; j++){  //check if imgObj is in ref list
  259.         theName = document.MM_imgObjsArray[j].getAttribute("name");
  260.         if (theName == imgName) { //if imgObj there
  261.             imgSrcArray[j] = imgSrc;              //store imgSrc at that pos
  262.             imgSrcArray2[j] = imgSrc2;              //store imgSrc at that pos
  263.             if (imgSrc) addStarToMenuItem(document.theForm.menu,j);//if non-empty, mark with  *
  264.             found = true;
  265.             break;
  266.         }
  267.     }
  268.     if (!found) alert(errMsg(MSG_ImgNotFound,imgName,imgSrc)); //if image name not found
  269.   }
  270.   document.theForm.grpName.value = group;
  271.   document.MM_myImgSrcs = imgSrcArray; //save updated imageSrc list
  272.   document.MM_myImgSrcs2 = imgSrcArray2; //save updated imageSrc list
  273.   displayImgSrc();         //load the imageSrc for selected image
  274.  
  275.   //Determine if preloading, get id
  276.   if (i < argArray.length) document.preloadId = argArray[i]; //unique id exists, get it
  277.    document.theForm.preload.checked = (argArray.length > i); //if preload, check box
  278.  
  279.   //If restore checkbox is available, see if MM_swapImgRestore() exists, and check the box
  280.   var theObj = findObject("restoreOption");
  281.   if (theObj) { //restore checkbox is a possibility
  282.     var selObj=dreamweaver.getBehaviorElement();
  283.     if (selObj && selObj.tagName != "A") selObj = selObj.parentNode; //move out to A tag if needed
  284.     if (selObj && selObj.tagName == "A") if (document.theForm.restore) {
  285.       document.theForm.restore.checked = getHandler(selObj,'onMouseOut','GrpRestore', group);
  286.     }
  287.   }
  288. }
  289.  
  290. //Given the original function call, this parses out the args and updates
  291. //the code. If there's a preload id at the end of the arglist, deletes
  292. //the preload handler. If there's a swap restore call, deletes that.
  293.  
  294. function deleteBehavior(behFnCallStr){
  295.   var argArray,obj,selArr,selObj;
  296.  
  297.   obj = dreamweaver.getDocumentDOM("document").body;
  298.   argArray = extractArgs(behFnCallStr);//get new list of imgObj,imgSrc pairs
  299.   group=unescQuotes(argArray[1]);
  300.   var otherGrp = "GrpDown('"+group+"'";
  301.   if (obj.innerHTML.indexOf(otherGrp) == -1) {
  302.     // last down for this group.
  303.     delHandler(obj,"onLoad","InitGrp",group);
  304.   } 
  305.  
  306.   //Maybe remove preload handler
  307.   if ((argArray.length-2)%3 == 1) { //if extra arg
  308.     document.preloadId = argArray[argArray.length-1]; //unique id exists, get it
  309.     if (obj.innerHTML.indexOf(document.preloadId) == -1) // if swap image not just moved
  310.       delHandler(obj,"onLoad","MM_preloadImages",document.preloadId);
  311.   }
  312.  
  313. }
  314.  
  315.  
  316.  
  317. //***************** LOCAL FUNCTIONS  ******************
  318.  
  319. //Load the select menu with image names.
  320. //Also sets the global property MM_myImgSrcs to the right num of items.
  321.  
  322. function initializeUI(){
  323.   var niceNameSrcArray, nameArray, i, selTag="";
  324.   var imgSrcArray = new Array();
  325.   var imgSrcArray2 = new Array();
  326.  
  327.   //Determine if RESTORE is an option. If not, remove UI for it
  328.   //the dreamweaver.getBehaviorTag() check ensures the checkbox
  329.   //is not available if a behavior is attached to a timeline
  330.       var removeCheckbox = false;
  331.       if (!dreamweaver.getBehaviorTag() )  //if behavior is in a timeline
  332.         removeCheckbox = true;
  333.       else{
  334.         if (dreamweaver.getBehaviorElement()) selTag = dreamweaver.getBehaviorElement().tagName;
  335.         if (!selTag) selTag = getSelectionTag();
  336.         if (selTag!="A" && selTag!="IMG")  //if sel not A or IMG
  337.           removeCheckbox = true;
  338.       }  
  339.       if (removeCheckbox){
  340.         var theObj = findObject("restoreOption");
  341.         if (theObj) theObj.outerHTML = ""; //remove restoreOption checkbox
  342.       }
  343.   
  344.  
  345.   //Create unique ID in case of preload
  346.   document.preloadId = "#"+((new Date()).getTime());
  347.  
  348.   //Build and load picklist of images
  349.   niceNameSrcArray = getAllObjectRefs("IE 4.0","IMG");
  350.   nameArray = niceNames(niceNameSrcArray,TYPE_Image);
  351.   for (i=0; i<nameArray.length; i++){
  352.     document.theForm.menu.options[i]=new Option(nameArray[i]); //load menu
  353.     imgSrcArray[i] = "";
  354.     imgSrcArray2[i] = "";
  355.   }
  356.   pickSelectedImage(); //if an image is selected, selects it in the picklist
  357.   document.MM_myImgSrcs = imgSrcArray; //set global
  358.   document.MM_myImgSrcs2 = imgSrcArray2; //set global
  359.  
  360.   document.theForm.imgSrc.focus(); //set focus on textbox
  361.   document.theForm.imgSrc.select(); //set insertion point into textbox
  362. }
  363.  
  364. //Given imageSrc in form, looks up the menu's selection number, and stores the
  365. //new imageSrc at that position in the global document property "MM_myImgSrcs".
  366.  
  367. function storeImgSrc(){
  368.   var newImgSrc, imgSrcArray, menuIndex, newMenuText;
  369.  
  370.   newImgSrc = document.theForm.imgSrc.value;
  371.   imgSrcArray = document.MM_myImgSrcs; //get the prior list of imgSrcs
  372.   menuIndex = document.theForm.menu.selectedIndex; //get index to swap
  373.   imgSrcArray[menuIndex] = newImgSrc;   //swap
  374.   document.MM_myImgSrcs = imgSrcArray;   //rewrite list
  375.   if (newImgSrc) {  //if non-empty, mark with  *
  376.     addStarToMenuItem(document.theForm.menu, menuIndex);
  377.   } else { //nothing to store, strip off any previous star
  378.     newMenuText = stripStar(document.theForm.menu.options[menuIndex].text); //remove if old star
  379.     document.theForm.menu.options[menuIndex]=new Option(newMenuText); //add new line to menu
  380.   }
  381.   document.theForm.menu.selectedIndex = menuIndex; //reset selection index
  382. }
  383.  
  384. function storeImgSrc2(){
  385.   var newImgSrc, imgSrcArray2, menuIndex, newMenuText;
  386.  
  387.   newImgSrc = document.theForm.imgSrc2.value;
  388.   imgSrcArray2 = document.MM_myImgSrcs2; //get the prior list of imgSrcs
  389.   menuIndex = document.theForm.menu.selectedIndex; //get index to swap
  390.   imgSrcArray2[menuIndex] = newImgSrc;   //swap
  391.   document.MM_myImgSrcs2 = imgSrcArray2;   //rewrite list
  392.   if (newImgSrc) {  //if non-empty, mark with  *
  393.     addStarToMenuItem(document.theForm.menu, menuIndex);
  394.   } else { //nothing to store, strip off any previous star
  395.     newMenuText = stripStar(document.theForm.menu.options[menuIndex].text); //remove if old star
  396.     document.theForm.menu.options[menuIndex]=new Option(newMenuText); //add new line to menu
  397.   }
  398.   document.theForm.menu.selectedIndex = menuIndex; //reset selection index
  399. }
  400.  
  401.  
  402.  
  403. //Looks at the menu of names, and returns the imgSrc associated with the
  404. //selected item. Example: if the 2nd menu item's selected, returns 2nd item
  405. //stored in property "MM_myImgSrcs".
  406.  
  407. function displayImgSrc(){
  408.   var imgSrcArray, imgSrcArray2, curImageSrcNum, imgSrc, imgSrc2;
  409.  
  410.   imgSrcArray = document.MM_myImgSrcs; //get the list of imgSrcs
  411.   imgSrcArray2 = document.MM_myImgSrcs2; //get the list of imgSrcs
  412.   curImageSrcNum = document.theForm.menu.selectedIndex; //get index selected
  413.   imgSrc = imgSrcArray[curImageSrcNum];   //lookup imgSrc
  414.   imgSrc2 = imgSrcArray2[curImageSrcNum];   //lookup imgSrc
  415.   document.theForm.imgSrc.value= imgSrc;    //write into text field
  416.   document.theForm.imgSrc2.value= imgSrc2;    //write into text field
  417. }
  418.  
  419.  
  420.  
  421. //Invokes dialog to allow user to select filename. Puts value in text input.
  422.  
  423. function browseFileAndStore(){
  424.   var fileName;
  425.   fileName = browseForFileURL("select", "", true);  //returns a local filename
  426.   if (fileName) {
  427.     document.theForm.imgSrc.value = fileName;
  428.     storeImgSrc();
  429.   }
  430. }
  431.  
  432. //Invokes dialog to allow user to select filename. Puts value in text input.
  433.  
  434. function browseFileAndStore2(){
  435.   var fileName;
  436.   fileName = browseForFileURL("select", "", true);  //returns a local filename
  437.   if (fileName) {
  438.     document.theForm.imgSrc2.value = fileName;
  439.     storeImgSrc2();
  440.   }
  441. }
  442.  
  443.  
  444. function pickSelectedImage(){
  445.   var imgsArray = document.MM_imgObjsArray = createObjsArray("IMG");
  446.   var arrLen = imgsArray.length;
  447.   var selArr = dreamweaver.getSelection();
  448.   var selObj = dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  449.   
  450.   for (i=0;i<arrLen;i++){
  451.     if (imgsArray[i]==selObj)
  452.       document.theForm.menu.selectedIndex=i;  
  453.   }
  454. }
  455.  
  456. function identifyBehaviorArguments(fnCallStr) {
  457.   var argList, argArray, numArgGroups, i;
  458.  
  459.   argList = "ignore"; /* ignore the group name */
  460.   argArray = extractArgs(fnCallStr);
  461.   numArgGroups = (argArray.length - 2) / 3; //args come in triples
  462.   for (i=0; i<numArgGroups; i++) {          //with each NSobj,IEobj,URL triplet
  463.     argList += ((argList)?",":"")+"ignore,DEP,DEP";
  464.   }
  465.   return argList;
  466. }
  467.  
  468. //Creates a unique name for objs of tagName, using tagString
  469. //for instance: if tagString = Image, returns a name like Image1
  470. function getUniqueName(tagName,tagString,tagNameObjsArray){ 
  471.   var frameListSize,objName,dupe=true,counter=1;
  472.   var objsArray=arguments[2],objsArrayLen = objsArray.length;
  473.   
  474.     while (dupe==true){ //check new name against name of all other tagName objs
  475.         dupe=false;
  476.         objName = tagString + counter++; 
  477.         //iterates through possible names: tagName1, then tagName2, etc.
  478.         for (i=0;dupe==false && i<objsArrayLen;i++){
  479.           //if another object of this type has the same name
  480.           if (objsArray[i].getAttribute("name") == objName) 
  481.             dupe=true; //then repeat the loop, trying a new name
  482.         }
  483.     }
  484.     return objName; //return new name 
  485.     
  486. }
  487.  
  488. //Returns an array of objects of tagName
  489. //If doc is in a frameset, searches all frames in parent
  490. function createObjsArray(tagName){
  491.   var frameListLen,objsArray=new Array(),thisFrame;
  492.   if (dreamweaver.getDocumentDOM('parent')){//if frames
  493.     frameListLen = dreamweaver.getDocumentDOM('parent').getElementsByTagName('frame').length;
  494.     for (i=0;i<frameListLen;i++){
  495.       thisFrame = 'parent.frames[' + i + ']';
  496.       objsArray = objsArray.concat(dreamweaver.getDocumentDOM(thisFrame).getElementsByTagName(tagName));
  497.     }
  498.   } else //if no frames
  499.     objsArray = dreamweaver.getDocumentDOM("document").getElementsByTagName(tagName);
  500.   return objsArray;     
  501. }
  502.  
  503. //*************** GENERIC DOM MANIPULATION FNS *****************
  504.  
  505. //Returns a function call if exists in event handler.
  506. //  obj       - DOM object, such as dreamweaver.getDocumentDOM().body
  507. //  eventName - "onLoad", "onClick" etc (not case sensitive)
  508. //  fnName    - "MM_preloadImages" etc.
  509. //  optStr    - (optional) function call must contain this string to be found
  510. //Given <TAG onEvent="aaa();bbb();ccc()">,
  511. //calling getHandler(tagObj,'onEvent','bbb') will
  512. //return "bbb()". Returns empty if event or fn don't exist.
  513.  
  514. function getHandler(obj,eventName,fnName, optStr) {
  515.   var eventStr,fnArray,i,theChunk,retVal = "";
  516.   eventStr = obj.getAttribute(eventName);
  517.   if (eventStr) { //find previous call, or add it
  518.     fnArray = dreamweaver.getTokens(eventStr,";");
  519.     for (i=0; i<fnArray.length; i++) { //look at each code chunk
  520.       if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr ||  //fn call found
  521.           fnArray[i].indexOf(optStr) != -1)) {
  522.         retVal = fnArray[i]; break;
  523.     } }
  524.   }
  525.   return retVal
  526. }
  527.  
  528.  
  529.  
  530. //Replaces or adds a fn call to an event handler
  531. //  obj       - DOM object, such as dreamweaver.getDocumentDOM().body
  532. //  eventName - "onLoad", "onClick" etc (not case sensitive)
  533. //  fnCall    - "myFun('arg1','arg2')" etc.
  534. //  optStr    - (optional) function call must contain this string to be found
  535. //Given <TAG onEvent="aaa();bbb();ccc()">,
  536. //calling setHandler(tagObj,'onEvent','bbb(1,2)') will
  537. //replace "bbb()" with the altered fn call. If the event
  538. //does not exist, adds it. It fn didn't exist, adds it to the
  539. //end of the list.
  540.  
  541. function setHandler(obj,eventName,fnCall, optStr) {
  542.   var eventStr,fnName,fnArray=new Array(),i=0;
  543.   eventStr = obj.getAttribute(eventName);
  544.   if (eventStr) { //if event exists
  545.     fnName = fnCall.substring(0,fnCall.indexOf("("));
  546.     fnArray = dreamweaver.getTokens(eventStr,";");
  547.     for (i; i<fnArray.length; i++) //search for fnName
  548.       if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr ||  //fn call found
  549.           fnArray[i].indexOf(optStr) != -1)) break;
  550.   }
  551.   fnArray[i] = fnCall;
  552.   obj.setAttribute(eventName,fnArray.join(";"));
  553.   return true
  554. }
  555.  
  556.  
  557.  
  558. //Deletes a fn call from an event handler
  559. //  obj       - DOM object, such as dreamweaver.getDocumentDOM().body
  560. //  eventName - "onLoad", "onClick" etc (not case sensitive)
  561. //  fnName    - "MM_preloadImages" etc.
  562. //  optStr    - (optional) function call must contain this string to be found
  563. //Given <TAG onEvent="aaa();bbb();ccc()">,
  564. //calling delHandler(tagObj,'onEvent','bbb') will
  565. //remove "bbb();". If it is the last fn in the handler,
  566. //removes the event entirely.
  567.  
  568. function delHandler(obj,eventName,fnName, optStr) {
  569.   var eventStr,fnArray=new Array(),i=0,j;
  570.   eventStr = obj.getAttribute(eventName);
  571.   if (eventStr) { //if event exists
  572.     fnArray = dreamweaver.getTokens(eventStr,";");
  573.     for (i; i<fnArray.length; i++) { //look at each code chunk
  574.       if (fnArray[i].indexOf(fnName+'(') != -1 && (!optStr ||  //fn call found
  575.           fnArray[i].indexOf(optStr) != -1)) { //and, if given, optStr exists
  576.         if (fnArray.length == 1) { //if last one, remove attribute
  577.           obj.removeAttribute(eventName);
  578.         } else { //pull out
  579.           for (j=i; j<fnArray.length; j++) fnArray[j] = fnArray[j+1]; //shift array
  580.           fnArray.length--;
  581.           obj.setAttribute(eventName,fnArray.join(';'));
  582.         }
  583.         break;
  584.     } }
  585.   }
  586.   return true
  587. }
  588.  
  589.  
  590.  
  591. //Returns the tag for the current selection, such as
  592. //IMG, A, DIV etc. Always uppercase.
  593.  
  594. function getSelectionTag() {
  595.   var retVal = "";
  596.   var selArr = dreamweaver.getSelection()
  597.   var selObj=dreamweaver.offsetsToNode(selArr[0],selArr[1]);
  598.     if (selObj && selObj.tagName) retVal = selObj.tagName;
  599.   return retVal
  600. }
  601.  
  602. //**************** GENERIC FUNCTIONS ****************
  603.  
  604. //function extractArgs(behFnCallStr){
  605. //function stripStar(theStr) {
  606. //function addStarToMenuItem(theSelect,menuIndex) {
  607. //function escQuotes(theStr){
  608. //function unescQuotes(theStr){
  609. //function niceNames(objRefArray,objTypeStr) {
  610. //function nameReduce (objName) {
  611. //function errMsg() {
  612. //function findObject(objName,  parentObj) {
  613.  
  614.  
  615.  
  616. //**************** GENERIC FUNCTIONS ****************
  617.  
  618. //function extractArgs(behFnCallStr){
  619. //function stripStar(theStr) {
  620. //function addStarToMenuItem(theSelect,menuIndex) {
  621. //function escQuotes(theStr){
  622. //function unescQuotes(theStr){
  623. //function niceNames(objRefArray,objTypeStr) {
  624. //function nameReduce (objName) {
  625. //function errMsg() {
  626. //function findObject(objName,  parentObj) {
  627.